package com.web.utils;

import java.util.Map;

public class Pager {

	/**
	 * 添加mysql分页参数（limitIndex，limitSize）
	 * 
	 * @param jsonMap
	 *            请求参数集合
	 * @return Map<String ,Object>
	 */
	public static void addPage(Map<String, Object> map) {
		Integer pageIndex = (Integer) map.get("pageNum");
		Integer pageSize = (Integer) map.get("pageSize");
		if (pageIndex == null) {
			pageIndex = 1;
		}
		if (pageSize == null) {
			pageSize = 10;
		}
		map.put("limitIndex", (int) (pageIndex - 1) * pageSize);
		map.put("limitSize", (int) pageSize);
	}

	public static int getPages(int total, int pageSize) {
		int pages = 0;
		if (total % pageSize == 0) {
			pages = total / pageSize;
		} else {
			pages = total / pageSize + 1;
		}
		return pages;
	}
}
